//
//  BaseTableView.m
//  ArtDog
//
//  Created by dllo on 16/8/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BaseTableView.h"

@interface BaseTableView ()

@property (nonatomic, copy) NumberOfSection numberOfSection;
@property (nonatomic, copy) NumberOfRow numberOfRow;
@property (nonatomic, copy) CellForRowAtIndexPath cellForRowAtIndexPath;
@property (nonatomic, copy) HeightForRowAtIndexPath heightForRowAtIndexPath;
@property (nonatomic, copy) DidSelectRowAtIndexPath didSelectRowAtIndexPath;
@property (nonatomic, strong) TableViewReturnParam *tableViewParam;

@end

@implementation BaseTableView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupTableView];
        
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self setupTableView];
        
    }
    return self;
}

- (void)setupTableView
{

}


- (void)tableViewWithNumberOfSection:(NumberOfSection)numberOfSection andNumberOfRow:(NumberOfRow)numberOfRow andCellForRowAtIndexPath:(CellForRowAtIndexPath)cellForRowAtIndexPath andHeightForRowAtIndexPath:(HeightForRowAtIndexPath)heightForRowAtIndexPath andDidSelectRowAtIndexPath:(DidSelectRowAtIndexPath)didSelectRowAtIndexPath
{
    self.delegate = self;
    self.dataSource = self;
    _numberOfRow = numberOfRow;
    _numberOfSection = numberOfSection;
    _cellForRowAtIndexPath = cellForRowAtIndexPath;
    _heightForRowAtIndexPath = heightForRowAtIndexPath;
    _didSelectRowAtIndexPath = didSelectRowAtIndexPath;
    _tableViewParam = [[TableViewReturnParam alloc]init];
}

- (void)tableViewWithNumberOfRow:(NumberOfRow)numberOfRow andCellForRowAtIndexPath:(CellForRowAtIndexPath)cellForRowAtIndexPath andHeightForrowAtIndexPath:(HeightForRowAtIndexPath)heightForRowAtIndexPath andDidSelectRowAtIndexPath:(DidSelectRowAtIndexPath)didSelectRowAtIndexPath
{
    [self tableViewWithNumberOfSection:^(UITableView * _Nonnull tableView, TableViewReturnParam * _Nonnull tableViewParam) {
        
    } andNumberOfRow:numberOfRow andCellForRowAtIndexPath:cellForRowAtIndexPath andHeightForRowAtIndexPath:heightForRowAtIndexPath andDidSelectRowAtIndexPath:didSelectRowAtIndexPath];
}

- (void)tableViewWithNumberOfRow:(NumberOfRow)numberOfRow andCellForRowAtIndexPath:(CellForRowAtIndexPath)cellForRowAtIndexPath andHeightForrowAtIndexPath:(HeightForRowAtIndexPath)heightForRowAtIndexPath
{
    [self tableViewWithNumberOfSection:^(UITableView * _Nonnull tableView, TableViewReturnParam * _Nonnull tableViewParam) {
        
    } andNumberOfRow:numberOfRow andCellForRowAtIndexPath:cellForRowAtIndexPath andHeightForRowAtIndexPath:heightForRowAtIndexPath andDidSelectRowAtIndexPath:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger numberSection = 1;
    self.numberOfSection(tableView, _tableViewParam);
    if (_tableViewParam.numberOfSection > 0) {
        numberSection = _tableViewParam.numberOfSection;
    }
    return numberSection;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger numberOfRow = 1;
    self.numberOfRow(tableView, _tableViewParam);
    numberOfRow = _tableViewParam.numberOfRow;
    return numberOfRow;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    self.cellForRowAtIndexPath(tableView, indexPath, _tableViewParam);
    cell = _tableViewParam.returnCell;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 44;
    self.heightForRowAtIndexPath(tableView, indexPath, _tableViewParam);
    height = _tableViewParam.heightAtRow;
    return height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    self.didSelectRowAtIndexPath(tableView, indexPath);
}

@end

@implementation TableViewReturnParam

- (instancetype)init
{
    self = [super init];
    if (self) {
        _numberOfSection = 1;
        _heightAtRow = 44;
    }
    return self;
}

@end
